<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@page import="org.apache.commons.lang3.StringUtils"%>
<%@page import="cc.tongyuan.dcsystem.sys.domainmodel.SystemModel"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<jsp:include page="../inc/meta.jsp"></jsp:include>
<jsp:include page="../inc/easyui.jsp"></jsp:include>
</head>
  <body class="easyui-layout" fit="true">
  	 <div region="center" border="false" style="padding: 10px; border: 1px solid #ccc;">
        <form id="frmUserLoginLimit" action="" method="post">
          <input type="hidden" id="userId" name="userId" value="${userId}"/>
        <table class="data-form" cellspacing="0" cellpadding="0">
            <tr>
                <th scope="row">
                    用户：
                </th>
                <td>
                    ${userName}
                </td>
            </tr>
            <tr>
                <th scope="row">
                    所在系统：
                </th>
				<td><select id="systemId" name="systemId" onChange="doChangeSystem();">
						<option value="">=请选择系统=</option>
					<%for(SystemModel system : (List<SystemModel>)request.getAttribute("systemList")){%>
								<option value="<%=system.getId()%>"><%=system.getName()%></option>
								<%
									}
								%>
				 </select></td>
            </tr>
            <%if (request.getParameter("systemId")!=null){%>
                <tr>
                    <th scope="row">
                        &nbsp;
                    </th>
                    <td>
                    	<input name="loginEnabled" type="checkbox" value="${loginLimit.loginEnabled }"/>允许登录
                    </td>
                </tr>
                <tr>
                    <th scope="row">
                        &nbsp;
                    </th>
                    <td>
                       <input name="ipLimited" type="checkbox" vlue="${loginLimit.ipLimited }"/>限制登录IP
                    </td>
                </tr>
                <tr>
                    <th scope="row">
                        允许登录的IP集：
                    </th>
                    <td>
                    	<textarea name="allowedIpSet" value="${loginLimit.allowedIpSet}" rows="" cols="" style="resize: none; width: 294px"></textarea>
                    </td>
                </tr>
                <tr>
                    <th scope="row">
                    </th>
                    <td class="txt-gray">
                        说明：多个IP时，请以“|”分隔。
                    </td>
                </tr>
                <tr>
                    <th scope="row">
                        &nbsp;
                    </th>
                    <td>
                    	<input type="checkbox" name="timeLimited" value="${loginLimit.timeLimited}"/>限制登录时间
<!--                         @Html.CheckBoxFor(m => m.TimeLimited)限制登录时间 -->
                    </td>
                </tr>
                <tr>
                    <th scope="row">
                        允许登录的开始时间：
                    </th>
                    <td>
                    	<input type="text" name="allowedBeginTimeOfDay" value="${loginLimit.allowedBeginTimeOfDay}" class="easyui-timespinner" showSeconds = "true" style="width: 168px;" />
<!--                         @Html.TextBoxFor(m => m.AllowedBeginTimeOfDay, new { @class = "easyui-timespinner", showSeconds = "true", style = "width: 168px;" }) -->
                    </td>
                </tr>
                <tr>
                    <th scope="row">
                        允许登录的结束时间：
                    </th>
                    <td>
                    	<input type="text" name="allowedEndTimeOfDay" value="${loginLimit.allowedEndTimeOfDay}" class="easyui-timespinner" showSeconds = "true" style="width: 168px;" />
                    </td>
                </tr>
                <tr>
                    <th scope="row">
                    </th>
                    <td class="txt-gray">
                        说明：当选择了启用权限，此用户在开始日期至结束日期内登录系统，权限是生效的。
                    </td>
                </tr>
            <%} %>
        </table>
        </form>
    </div>
    <div region="south" border="false" style="text-align: right; padding: 5px 0;">
        <a class="easyui-linkbutton" iconcls="icon-save" href="javascript:doSubmit('/taskpro/user/editLoginLimit.do');">
            保存</a> <a class="easyui-linkbutton" iconcls="icon-cancel" href="javascript:top.closeMyWindow()">
                取消</a>
    </div>
    <script type="text/javascript">
        $(function () {
        //TODO:再点击Checkbox之后，开始时间和结束时间才能用
           $('#systemId').val('${systemId}');
        });




        function doChangeSystem() {
            var userId = $('#userId').trim();
            var systemId = $('#systemId').trim();

            var url = '/taskpro/user/toEditLoginLimit.do';
            location.href = $.format(url + '?userId={0}&systemId={1}', $.encode(userId), $.encode(systemId));
        }

        function doSubmit(url) {
            var systemIndex = $('#systemId').get(0).selectedIndex;
            if (systemIndex == 0) {
                top.showMsg('提示', '请选择所在系统！');
                return;
            }
            //TODO:验证结束日期大于开始日期
            $('#frmUserLoginLimit').form('submit', {
                url: url,
                onsubmit: function () {
                    var flag = $(this).form('validate');
                    if (flag) {
                        top.showProcess(true, '温馨提示', '正在提交数据...');
                    }
                    return flag;
                },
                success: function (data) {
                    showProcess(false);
                    var map = $.parseJSON(data);
                    if (map.success) {
                        top.showMsg('提示', map.msg);
                        //parent.reloadDataGrid();
                        parent.closeMyWindow();
                    }
                    else {
                        top.showMsg('警告', map.msg);
                    }

                },
                onLoadError: function () {
                    top.showProcess(false);
                    top.$.messager.alert('温馨提示', '由于网络或服务器太忙，提交失败，请重试！');
                }

            });

        }
    </script>
</body>

</html>
